package cn.z2huo.knowledge.concurrency.synchronizedkeyword.reentrant;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 *
 * @author z2huo
 */
class SyncMethodTest implements Runnable {

    public synchronized void methodA() {
        System.out.println(Thread.currentThread().threadId() + " methodA");
        methodB();
    }

    public synchronized void methodB() {
        System.out.println(Thread.currentThread().threadId() + " methodB");
    }

    public static void main(String[] args) throws InterruptedException {
        SyncMethodTest syncMethodTest = new SyncMethodTest();

        Thread thread = new Thread(syncMethodTest);
        Thread thread2 = new Thread(syncMethodTest);
        thread.start();
        TimeUnit.SECONDS.sleep(1);
        thread2.start();
    }

    @Override
    public void run() {
        this.methodA();
    }
}
